package by.ins.life.work;


import java.util.List;

import by.ins.life.INuclear;
import by.yativem.commons.utils.math.IMath;
import by.yativem.commons.utils.math.MathProvider;

public class NuclearMatrixUtils<T> {
	
	protected IMath<T> math;
	
	public NuclearMatrixUtils(IMath<T> math ){
		this.math = math;
	}	
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static NuclearMatrixUtils getInstanceFor(Class clazz){
		return new NuclearMatrixUtils(MathProvider.getMathInstance(clazz));
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static NuclearMatrixUtils getInstanceFor(IMath<?> math){
		return new NuclearMatrixUtils(math);
	}
	
	/*
	 * return sum of states from List<T> 
	 */
	public  T getSum(List<INuclear<T>> list ){		
		
		T result = math.getZero();
		
		for(INuclear<T> n : list){
			result = math.add(result, n.getState() );
		}
		
		return result;
	}
	
	public T getWeightedSum(List<INuclear<T>> list){
		
		T result = math.getZero();
		
		for(INuclear<T> n : list){
			result = math.add(result, math.maltiplicate(n.getState(), n.getWeight()) );
		}
		
		return result; 
	}
	
	

	

}
